package tech.aichan.AiQA.model.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import tech.aichan.AiQA.model.entity.Item;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author mengyu
 * @date 2024/03/03 10:12
 */
@Data
public class ItemVO implements Serializable {
    private Long id;

    private String itemName;

    private Double price;

    // Json数组
    private List<String> tags;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
    private Date createTime;

    @Serial
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public static ItemVO getItemVOByItem(Item item){
        if(item == null){
            return null;
        }
        ItemVO itemVO = new ItemVO();
        BeanUtils.copyProperties(item,itemVO);
        // 转为List
        itemVO.setTags(Arrays.stream(item.getTags().split(",")).toList());
        return itemVO;
    }
}
